﻿using RepositoryAndEf.Core.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RepositoryAndEf.Service;
using System.Data.Entity;
using RepositoryAndEf.Data;
using RepositoryAndEf.Data.Migrations;
using RepositoryAndEf.Core.Data;
using RepositoryAndEf.Domain;
using System.Runtime.InteropServices;

namespace RepositoryAndEf.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<RepositoryAndEfContext, Configuration>());
            
            ////initialize engine context
            //EngineContext.Initialize(false);

            //var userRepository = EngineContext.Current.Resolve<IRepository<User>>();
            //var users = userRepository.Get(u => true);


            using (IUnitOfWork uow = new RepositoryAndEfContext("ConnStr"))
            {
                var userRepository = new EfRepository<User>(uow);
                var productRepository = new EfRepository<Product>(uow);

                productRepository.Insert(new Product { Id = Guid.NewGuid(), Title = "IPad 10" });
                userRepository.Insert(new User { Name = "Jesse Liu" });

                uow.SaveChanges();
            }

            //var userService = EngineContext.Current.Resolve<IUserService>();

            //bool isExisted = userService.IsEmailExisted("hellojesseliu@outlook.com");
            //System.Console.Write("Is existed? :{0}", isExisted);

            //userService.Register("hellojesseliu@outlook.com", "Jesse Liu", "admin");
            //isExisted = userService.IsEmailExisted("hellojesseliu@outlook.com");
            //System.Console.Write("Is existed? :{0}", isExisted);

            System.Console.ReadLine();
        }
    }
}
